package com.lemon.core.common.web.notify.dingding;

import com.lemon.core.common.web.notify.dingding.bean.DingNotifyData;

/**
 * @author lemon
 * @ClassName DingNotifyDataBuilder
 * @desc 钉钉消息构造器
 * @Date 2019/3/9 15:00
 * @Version 1.0
 **/
public class DingNotifyDataBuilder {

    public interface Constants {

        public static final String TEXT_TYPE = "text";

        public static final String LINK_TYPE = "link";

        public static final String MARKDOWN_TYPE = "markdown";

        public static final String ACTIONCARD_TYPE = "actionCard";

        public static final String WRAP_LINE = "\\n- ";
    }

    // -------------------- 构建ActionCard类型消息 --------------------

    public static DingNotifyData buildActionCardMsg(String title, String... contents) {
        DingNotifyData dingNotifyData = new DingNotifyData();
        dingNotifyData.setTitle("猫扑技术部机器人");
        StringBuffer contentBuffer = new StringBuffer("### " + title).append(Constants.WRAP_LINE);
        for (String content : contents) {
            contentBuffer.append(content).append(Constants.WRAP_LINE);
        }
        contentBuffer.delete(contentBuffer.length() - Constants.WRAP_LINE.length(), contentBuffer.length());
        dingNotifyData.setContent(contentBuffer.toString());
        dingNotifyData.setHideAvatar("0");
        dingNotifyData.setBtnOrientation("0");
        dingNotifyData.setMsgtype(Constants.ACTIONCARD_TYPE);
        return dingNotifyData;
    }

    // -------------------- 构建ActionCard类型消息 --------------------
}
